package controller.goods;

import BaseController.BaseController;
import Servlet.HttpServletRequest;
import entity.goods.dto.GoodsNewsTypeAddDTO;
import entity.goods.dto.GoodsNewsTypeUpdateDTO;
import entity.goods.example.GoodsNewsTypeExample;
import entity.goods.pojo.GoodsNewsType;
import model.goods.GoodsNewsTypeModel;
import response.JsonResult;
import response.PageVO;
import response.PagerInfo;
import response.SldResponse;
import util.CollectionUtils;
import util.WebUtil;
import vo.goods.GoodsNewsTypeVO;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

//@Api(tags = "admin-新闻类型")
//@RestController
//@RequestMapping("v3/goods/admin/goodsNewsType")
public class GoodsNewsTypeController extends BaseController {

    @Resource
    private GoodsNewsTypeModel goodsNewsTypeModel;

    /*@ApiOperation("新闻类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsTypeName", value = "新闻类型名称", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", defaultValue = "20", paramType = "query"),
            @ApiImplicitParam(name = "current", value = "当前页面位置", defaultValue = "1", paramType = "query")
    })
    @GetMapping("list")*/
    public JsonResult<PageVO<GoodsNewsTypeVO>> getList(HttpServletRequest request, String newsTypeName) {
        //分页设置
        PagerInfo pager = WebUtil.handlerPagerInfo(request);
        //你好
        //根据新闻类型名称查询新闻类型集合
        GoodsNewsTypeExample example = new GoodsNewsTypeExample();
        //给example对象中的新闻类型名称变量赋值
        example.setNewsTypeName(newsTypeName);
        example.setOrderBy("sort asc,news_type_id asc");
        List<GoodsNewsType> list = goodsNewsTypeModel.getGoodsNewsTypeList(example,pager);

        ArrayList<GoodsNewsTypeVO> vos = new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(goodsNewsType -> {
                GoodsNewsTypeVO vo = new GoodsNewsTypeVO(goodsNewsType);
                vos.add(vo);
            });
        }
        return SldResponse.success(new PageVO<>(vos, pager));
    }

    /*@ApiOperation("批量删除新闻类型")
    @OperationLogger(option = "批量删除新闻类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsTypeIds", value = "新闻类型id", required = true)
    })
    @PostMapping("delGoodsNewsTypeByIds")*/
    public JsonResult delGoodsNewsTypeByIds(HttpServletRequest request, String newsTypeIds) {
        goodsNewsTypeModel.delGoodsNewsTypeByIds(newsTypeIds);
        return SldResponse.success("删除成功");
    }

    /*@ApiOperation("新增新闻类型")
    @OperationLogger(option = "新增新闻类型")
    @PostMapping("add")*/
    public JsonResult addGoodsNewsType(HttpServletRequest request, GoodsNewsTypeAddDTO goodsNewsTypeAddDTO) throws Exception {
        goodsNewsTypeModel.saveGoodsNewsType(goodsNewsTypeAddDTO);
        return SldResponse.success("保存成功");
    }

    /*@ApiOperation("编辑新闻类型")
    @OperationLogger(option = "编辑新闻类型")
    @PostMapping("edit")*/
    public JsonResult editGoodsNewsType(HttpServletRequest request, GoodsNewsTypeUpdateDTO goodsNewsTypeUpdateDTO) throws Exception {
        goodsNewsTypeModel.updateGoodsNewsType(goodsNewsTypeUpdateDTO);
        return SldResponse.success("修改成功");
    }
}

